<script setup lang="ts">
import { ref ,inject} from "vue";
import { addRoles } from "@/service/api";
import { ElMessage } from "element-plus";
const visible = ref(false)
const defaultFrom = {
  name: '',
  description: '',
  sort: 0
}
// 表单数据
const fromModel = ref({ ...defaultFrom });
const getRoleList = inject<any>('getRoleList')
const open = () =>{
  visible.value = true
}
const saveRole = async () => {
  await addRoles(fromModel.value).then(res => {
    ElMessage.success('添加角色信息成功！！！！')
    visible.value = false
    getRoleList()
  }).catch(err => {
    console.log(err);
  })
}
defineExpose({
    open
})
</script>


<template>
  <el-dialog v-model="visible" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form ref="dataFormRef" label-width="120px">
      <el-form-item label="角色名称" prop="name">
        <el-input placeholder="角色名称" v-model="fromModel.name"></el-input>
      </el-form-item>
      <el-form-item label="角色标识" prop="description">
        <el-input placeholder="角色标识" v-model="fromModel.description"></el-input>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="fromModel.sort" class="mx-4" :min="0" :max="10" controls-position="right" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span>
        <el-button @click="visible = false" style="margin-right: 10px;">取消</el-button>
        <el-button type="primary" @click="saveRole">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped lang="less"></style>